// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Fluent;
using Elastic.Clients.Elasticsearch.Requests;
using Elastic.Clients.Elasticsearch.Serialization;
using Elastic.Transport;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.MachineLearning;

public sealed partial class EvaluateDataFrameRequestParameters : RequestParameters
{
}

/// <summary>
/// <para>Evaluates the data frame analytics for an annotated index.<br/>The API packages together commonly used evaluation metrics for various types<br/>of machine learning features. This has been designed for use on indexes<br/>created by data frame analytics. Evaluation requires both a ground truth<br/>field and an analytics result field to be present.</para>
/// </summary>
public sealed partial class EvaluateDataFrameRequest : PlainRequest<EvaluateDataFrameRequestParameters>
{
	internal override ApiUrls ApiUrls => ApiUrlLookup.MachineLearningEvaluateDataFrame;

	protected override HttpMethod StaticHttpMethod => HttpMethod.POST;

	internal override bool SupportsBody => true;

	internal override string OperationName => "ml.evaluate_data_frame";

	/// <summary>
	/// <para>Defines the type of evaluation you want to perform.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("evaluation")]
	public Elastic.Clients.Elasticsearch.MachineLearning.DataframeEvaluation Evaluation { get; set; }

	/// <summary>
	/// <para>Defines the `index` in which the evaluation will be performed.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("index")]
	public Elastic.Clients.Elasticsearch.IndexName Index { get; set; }

	/// <summary>
	/// <para>A query clause that retrieves a subset of data from the source index.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("query")]
	public Elastic.Clients.Elasticsearch.QueryDsl.Query? Query { get; set; }
}

/// <summary>
/// <para>Evaluates the data frame analytics for an annotated index.<br/>The API packages together commonly used evaluation metrics for various types<br/>of machine learning features. This has been designed for use on indexes<br/>created by data frame analytics. Evaluation requires both a ground truth<br/>field and an analytics result field to be present.</para>
/// </summary>
public sealed partial class EvaluateDataFrameRequestDescriptor<TDocument> : RequestDescriptor<EvaluateDataFrameRequestDescriptor<TDocument>, EvaluateDataFrameRequestParameters>
{
	internal EvaluateDataFrameRequestDescriptor(Action<EvaluateDataFrameRequestDescriptor<TDocument>> configure) => configure.Invoke(this);

	public EvaluateDataFrameRequestDescriptor()
	{
	}

	internal override ApiUrls ApiUrls => ApiUrlLookup.MachineLearningEvaluateDataFrame;

	protected override HttpMethod StaticHttpMethod => HttpMethod.POST;

	internal override bool SupportsBody => true;

	internal override string OperationName => "ml.evaluate_data_frame";

	private Elastic.Clients.Elasticsearch.MachineLearning.DataframeEvaluation EvaluationValue { get; set; }
	private Elastic.Clients.Elasticsearch.MachineLearning.DataframeEvaluationDescriptor<TDocument> EvaluationDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.MachineLearning.DataframeEvaluationDescriptor<TDocument>> EvaluationDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.IndexName IndexValue { get; set; }
	private Elastic.Clients.Elasticsearch.QueryDsl.Query? QueryValue { get; set; }
	private Elastic.Clients.Elasticsearch.QueryDsl.QueryDescriptor<TDocument> QueryDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.QueryDsl.QueryDescriptor<TDocument>> QueryDescriptorAction { get; set; }

	/// <summary>
	/// <para>Defines the type of evaluation you want to perform.</para>
	/// </summary>
	public EvaluateDataFrameRequestDescriptor<TDocument> Evaluation(Elastic.Clients.Elasticsearch.MachineLearning.DataframeEvaluation evaluation)
	{
		EvaluationDescriptor = null;
		EvaluationDescriptorAction = null;
		EvaluationValue = evaluation;
		return Self;
	}

	public EvaluateDataFrameRequestDescriptor<TDocument> Evaluation(Elastic.Clients.Elasticsearch.MachineLearning.DataframeEvaluationDescriptor<TDocument> descriptor)
	{
		EvaluationValue = null;
		EvaluationDescriptorAction = null;
		EvaluationDescriptor = descriptor;
		return Self;
	}

	public EvaluateDataFrameRequestDescriptor<TDocument> Evaluation(Action<Elastic.Clients.Elasticsearch.MachineLearning.DataframeEvaluationDescriptor<TDocument>> configure)
	{
		EvaluationValue = null;
		EvaluationDescriptor = null;
		EvaluationDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>Defines the `index` in which the evaluation will be performed.</para>
	/// </summary>
	public EvaluateDataFrameRequestDescriptor<TDocument> Index(Elastic.Clients.Elasticsearch.IndexName index)
	{
		IndexValue = index;
		return Self;
	}

	/// <summary>
	/// <para>A query clause that retrieves a subset of data from the source index.</para>
	/// </summary>
	public EvaluateDataFrameRequestDescriptor<TDocument> Query(Elastic.Clients.Elasticsearch.QueryDsl.Query? query)
	{
		QueryDescriptor = null;
		QueryDescriptorAction = null;
		QueryValue = query;
		return Self;
	}

	public EvaluateDataFrameRequestDescriptor<TDocument> Query(Elastic.Clients.Elasticsearch.QueryDsl.QueryDescriptor<TDocument> descriptor)
	{
		QueryValue = null;
		QueryDescriptorAction = null;
		QueryDescriptor = descriptor;
		return Self;
	}

	public EvaluateDataFrameRequestDescriptor<TDocument> Query(Action<Elastic.Clients.Elasticsearch.QueryDsl.QueryDescriptor<TDocument>> configure)
	{
		QueryValue = null;
		QueryDescriptor = null;
		QueryDescriptorAction = configure;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (EvaluationDescriptor is not null)
		{
			writer.WritePropertyName("evaluation");
			JsonSerializer.Serialize(writer, EvaluationDescriptor, options);
		}
		else if (EvaluationDescriptorAction is not null)
		{
			writer.WritePropertyName("evaluation");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.MachineLearning.DataframeEvaluationDescriptor<TDocument>(EvaluationDescriptorAction), options);
		}
		else
		{
			writer.WritePropertyName("evaluation");
			JsonSerializer.Serialize(writer, EvaluationValue, options);
		}

		writer.WritePropertyName("index");
		JsonSerializer.Serialize(writer, IndexValue, options);
		if (QueryDescriptor is not null)
		{
			writer.WritePropertyName("query");
			JsonSerializer.Serialize(writer, QueryDescriptor, options);
		}
		else if (QueryDescriptorAction is not null)
		{
			writer.WritePropertyName("query");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.QueryDsl.QueryDescriptor<TDocument>(QueryDescriptorAction), options);
		}
		else if (QueryValue is not null)
		{
			writer.WritePropertyName("query");
			JsonSerializer.Serialize(writer, QueryValue, options);
		}

		writer.WriteEndObject();
	}
}

/// <summary>
/// <para>Evaluates the data frame analytics for an annotated index.<br/>The API packages together commonly used evaluation metrics for various types<br/>of machine learning features. This has been designed for use on indexes<br/>created by data frame analytics. Evaluation requires both a ground truth<br/>field and an analytics result field to be present.</para>
/// </summary>
public sealed partial class EvaluateDataFrameRequestDescriptor : RequestDescriptor<EvaluateDataFrameRequestDescriptor, EvaluateDataFrameRequestParameters>
{
	internal EvaluateDataFrameRequestDescriptor(Action<EvaluateDataFrameRequestDescriptor> configure) => configure.Invoke(this);

	public EvaluateDataFrameRequestDescriptor()
	{
	}

	internal override ApiUrls ApiUrls => ApiUrlLookup.MachineLearningEvaluateDataFrame;

	protected override HttpMethod StaticHttpMethod => HttpMethod.POST;

	internal override bool SupportsBody => true;

	internal override string OperationName => "ml.evaluate_data_frame";

	private Elastic.Clients.Elasticsearch.MachineLearning.DataframeEvaluation EvaluationValue { get; set; }
	private Elastic.Clients.Elasticsearch.MachineLearning.DataframeEvaluationDescriptor EvaluationDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.MachineLearning.DataframeEvaluationDescriptor> EvaluationDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.IndexName IndexValue { get; set; }
	private Elastic.Clients.Elasticsearch.QueryDsl.Query? QueryValue { get; set; }
	private Elastic.Clients.Elasticsearch.QueryDsl.QueryDescriptor QueryDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.QueryDsl.QueryDescriptor> QueryDescriptorAction { get; set; }

	/// <summary>
	/// <para>Defines the type of evaluation you want to perform.</para>
	/// </summary>
	public EvaluateDataFrameRequestDescriptor Evaluation(Elastic.Clients.Elasticsearch.MachineLearning.DataframeEvaluation evaluation)
	{
		EvaluationDescriptor = null;
		EvaluationDescriptorAction = null;
		EvaluationValue = evaluation;
		return Self;
	}

	public EvaluateDataFrameRequestDescriptor Evaluation(Elastic.Clients.Elasticsearch.MachineLearning.DataframeEvaluationDescriptor descriptor)
	{
		EvaluationValue = null;
		EvaluationDescriptorAction = null;
		EvaluationDescriptor = descriptor;
		return Self;
	}

	public EvaluateDataFrameRequestDescriptor Evaluation(Action<Elastic.Clients.Elasticsearch.MachineLearning.DataframeEvaluationDescriptor> configure)
	{
		EvaluationValue = null;
		EvaluationDescriptor = null;
		EvaluationDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>Defines the `index` in which the evaluation will be performed.</para>
	/// </summary>
	public EvaluateDataFrameRequestDescriptor Index(Elastic.Clients.Elasticsearch.IndexName index)
	{
		IndexValue = index;
		return Self;
	}

	/// <summary>
	/// <para>A query clause that retrieves a subset of data from the source index.</para>
	/// </summary>
	public EvaluateDataFrameRequestDescriptor Query(Elastic.Clients.Elasticsearch.QueryDsl.Query? query)
	{
		QueryDescriptor = null;
		QueryDescriptorAction = null;
		QueryValue = query;
		return Self;
	}

	public EvaluateDataFrameRequestDescriptor Query(Elastic.Clients.Elasticsearch.QueryDsl.QueryDescriptor descriptor)
	{
		QueryValue = null;
		QueryDescriptorAction = null;
		QueryDescriptor = descriptor;
		return Self;
	}

	public EvaluateDataFrameRequestDescriptor Query(Action<Elastic.Clients.Elasticsearch.QueryDsl.QueryDescriptor> configure)
	{
		QueryValue = null;
		QueryDescriptor = null;
		QueryDescriptorAction = configure;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (EvaluationDescriptor is not null)
		{
			writer.WritePropertyName("evaluation");
			JsonSerializer.Serialize(writer, EvaluationDescriptor, options);
		}
		else if (EvaluationDescriptorAction is not null)
		{
			writer.WritePropertyName("evaluation");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.MachineLearning.DataframeEvaluationDescriptor(EvaluationDescriptorAction), options);
		}
		else
		{
			writer.WritePropertyName("evaluation");
			JsonSerializer.Serialize(writer, EvaluationValue, options);
		}

		writer.WritePropertyName("index");
		JsonSerializer.Serialize(writer, IndexValue, options);
		if (QueryDescriptor is not null)
		{
			writer.WritePropertyName("query");
			JsonSerializer.Serialize(writer, QueryDescriptor, options);
		}
		else if (QueryDescriptorAction is not null)
		{
			writer.WritePropertyName("query");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.QueryDsl.QueryDescriptor(QueryDescriptorAction), options);
		}
		else if (QueryValue is not null)
		{
			writer.WritePropertyName("query");
			JsonSerializer.Serialize(writer, QueryValue, options);
		}

		writer.WriteEndObject();
	}
}